package com.masterclient.app.modules.aftersale.adapter;

import android.text.Editable;
import android.text.TextWatcher;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.GridLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.masterclient.app.R;
import com.eoner.baselibrary.bean.aftersale.CommentProductBean;
import com.eoner.baselibrary.utils.GlideUtil;

import java.util.List;

import butterknife.BindView;

/**
 * 作者：sean
 * 创建时间：2017/8/8 16:49
 * 功能说明：
 */

public class CommentAdapter extends BaseQuickAdapter<CommentProductBean.DataBean.ShProductsBean, BaseViewHolder> {

    @BindView(R.id.tv_good_name)
    TextView tvGoodName;
    @BindView(R.id.tv_sku)
    TextView tvSku;
    @BindView(R.id.cb_check_high)
    CheckBox cbCheckHigh;
    @BindView(R.id.cb_check_mid)
    CheckBox cbCheckMid;
    @BindView(R.id.cb_check_low)
    CheckBox cbCheckLow;
    @BindView(R.id.et_comment)
    EditText etComment;
    @BindView(R.id.image)
    ImageView image;
    @BindView(R.id.rl_add_img)
    RelativeLayout rlAddImg;
    @BindView(R.id.gridLayout)
    GridLayout gridLayout;

    public CommentAdapter() {
        super(R.layout.item_comment);
    }

    @Override
    protected void convert(BaseViewHolder helper, CommentProductBean.DataBean.ShProductsBean item) {
        helper.setText(R.id.tv_good_name,item.getSh_name());
        GlideUtil.displayImage(mContext,item.getSh_image(),(ImageView) helper.getView(R.id.iv_goods),R.mipmap.defaults,60,60);
//        App.picasso.load(item.getSh_image()).resize(ScreenUtils.dp2px(60),ScreenUtils.dp2px(60)).into((ImageView) helper.getView(R.id.iv_goods));

        List<CommentProductBean.DataBean.ShProductsBean.ShAttributesBean> sh_attributes = item.getSh_attributes();

        String skus = "";
        if(sh_attributes!=null){
            for(CommentProductBean.DataBean.ShProductsBean.ShAttributesBean shAttributesBean:sh_attributes){
                skus+=("“"+shAttributesBean.getSh_alias_name()+"”");
            }
        }

        helper.setText(R.id.tv_sku,"规格："+skus);

        CheckBox checkBoxHigh = helper.getView(R.id.cb_check_high);
        CheckBox checkBoxMid = helper.getView(R.id.cb_check_mid);
        CheckBox checkBoxLow = helper.getView(R.id.cb_check_low);
        EditText et_comment = helper.getView(R.id.et_comment);
        TextView tv_high = helper.getView(R.id.tv_high);
        TextView tv_mid = helper.getView(R.id.tv_mid);
        TextView tv_low = helper.getView(R.id.tv_low);

        checkBoxHigh.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    checkBoxMid.setChecked(false);
                    checkBoxLow.setChecked(false);
                    item.setCheckLevel("1");
                    tv_high.setTextColor(0xd9000000);
                }else {
                    tv_high.setTextColor(0x4d000000);
                }
            }
        });
        checkBoxMid.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    checkBoxHigh.setChecked(false);
                    checkBoxLow.setChecked(false);
                    item.setCheckLevel("2");
                    tv_mid.setTextColor(0xd9000000);
                }else {
                    tv_mid.setTextColor(0x4d000000);
                }
            }
        });

        checkBoxLow.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    checkBoxMid.setChecked(false);
                    checkBoxHigh.setChecked(false);
                    item.setCheckLevel("3");
                    tv_low.setTextColor(0xd9000000);
                }else {
                    tv_low.setTextColor(0x4d000000);
                }
            }
        });

        checkBoxHigh.setChecked(true);

        et_comment.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                item.setComment(s.toString());
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });

        GridLayout gridLayout = helper.getView(R.id.gridLayout);
        RelativeLayout rlAddImg = helper.getView(R.id.rl_add_img);

        helper.addOnClickListener(R.id.rl_add_img);
        helper.setNestView(R.id.gridLayout);
    }

//    public interface OnUploadImageListener{
//        public void onAddImage();
//    }

}
